package com.three.productList.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.three.core.entity.Product;
import com.three.core.entity.Store;
import com.three.core.entity.StoreEvaluate;
import com.three.productList.feign.StoreFeign;
import com.three.productList.service.ProductListService;
import com.three.productList.util.Upload;
import com.three.productList.vo.*;
import com.three.core.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;




/**
 * @author ：li
 * @date ：Created in 2025/3/11 011 10:27
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/product/list")
public class ProductListController {
    @Autowired
    private ProductListService productListService;
    @Autowired
    private StoreFeign storeFeign;
    //查询店铺信息
    @GetMapping("/selectStore")
    public R<List<Store>> selectStoreByUserId(){
        return productListService.selectStoreByUserId();
    }

    //分页查询表单数据
    @PostMapping("/select")
    public R<IPage<ProductVo>> selectProduct(@RequestBody SearchForm searchForm){
        R<IPage<ProductVo>> iPageR = productListService.selectProduct(searchForm);
        return iPageR;
    }
    //删除
    @GetMapping("/deleteByProductId")
    public R<Product> deleteByProductId(Integer productId){
        return productListService.deleteByProductId(productId);
    }
    //添加
    @PostMapping("/insertProduct")
    public R<Product> insertProduct(@RequestBody Product product){
        return productListService.insertProduct(product);
    }
    //编辑按钮触发
    @PostMapping("/updateProduct")
    public R<Product> updateProduct(@RequestBody Product product){
        return productListService.updateProduct(product);
    }
    //上传图片
    @PostMapping ("/uploadFile")
    public R  upload(@RequestParam("file") MultipartFile file){
        String path = Upload.uploadOss(file);
        return new R<>(200,"上传成功",path);
    }
    @GetMapping("/selectAll")
    public R<List<Product>> selectAll(){
        return productListService.selectAll();
    }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    //手机端
    @RequestMapping("/selectProductAndStoreNameByProductName")
    public R<List<ProductMobileVo>> selectProductAndStoreNameByProductName(String productName){
        return productListService.selectProductAndStoreNameByProductName(productName);
    }


    //查询商品
    @PostMapping("/selectProductImagesByProductId")
    public R<List<Product>> selectProductImagesByProductId(Integer productId){
        return productListService.selectProductImagesByProductId(productId);
    }

    //手机端根据商品类型查询商品
    @PostMapping("/selectByType")
    public R<List<ProductAndStoreNameVo>> selectByType(Integer proTypeId, String productName) {
        return productListService.selectByType(proTypeId,productName);
    }
    //手机端 根据店铺id查询商品和店铺名称
    @PostMapping("/selectProductAndStoreNameByStoreId")
    public R<List<ProductMobileVo>> selectProductAndStoreNameByStoreId(String productName,Integer storeId){
        return productListService.selectProductAndStoreNameByStoreId(productName,storeId);
    }
    //获取商店的评价人数和评分星级
    @PostMapping("/selectEvaluateByStoreName")
    public R<StoreRatVo> selectStoreNameAndRatingByStoreName(String storeName){
        return storeFeign.selectEvaluateByStoreName(storeName);
    }

    //商品评价
    @PostMapping("/appraise")
    public R ppraise(@RequestBody ProductAppraiseVo productAppraiseVo){
        return productListService.ppraise(productAppraiseVo);
    }

}
